package com.nt.train.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * 03-配置文件演示-02
 * @author hlf
 * @version 1.0
 * @date 2022/7/28 11:13
 */
@RestController
public class ReadPropertiesEnvironment {

//    @Autowired
//    private AlipayProperties alipayProperties;

    @Value("${server.port}")
    private Integer port;

    @Value("${alipay.pay.appid}")
    private String appid;

    @Value("${alipay.pay.notify}")
    private String notify;

    @Value("${java.version}")
    private String javaVersion;

    @Value("${JAVA_HOME}")
    private String javaHome;

   // @Value("${MAVEN_HOME}" )
   //@Value("${server.web.domain:test}")
   @Value("${server.web.domain:#{null}}")
    private String mavenHome;

    @Value("${nan-name}")
    private String nanName;

    @Autowired
    private Environment environment;

    @GetMapping("/read/file")
    public Map<String,Object> readInfo(){
        Map<String,Object> map = new HashMap<>();
        map.put("port",environment.getProperty("server.port"));
        map.put("appid",environment.getProperty("alipay.pay.appid"));
        map.put("notify",environment.getProperty("alipay.pay.notify"));
        map.put("javaversion",environment.getProperty("java.version"));
        map.put("javahome",environment.getProperty("JAVA_HOME"));
        map.put("mavenhome",environment.getProperty("MAVEN_HOME"));
        return  map;
    }

    @GetMapping("/read/readInfo")
    public Map<String, Object> readInfo2() {
        Map<String, Object> map = new HashMap<>();
        map.put("port", port);
        map.put("appid", appid);
        map.put("notify", notify);
        map.put("javaversion", javaVersion);
        map.put("javahome", javaHome);
        map.put("mavenhome", mavenHome);
        return map;
    }

//    @GetMapping("/read/readInfo3")
//    public AlipayProperties readInfo3() {
//        return alipayProperties;
//    }
}
